// generating config files for a logical node
// Created: Apr. 13, 2023 by SUN Yazhou, asia.rabbit@163.com

#ifndef Port_h
#define Port_h

#include <fstream>
#include "types.h"

using std::ofstream;

class Port{
public:
  Port(bool isin, bool isshm, int lnid, int portid);
  virtual ~Port();

  void SetLnId1(int id){ fLnId1 = id; }
  /// \param isCMCSrc whether ipSrc is of CMC
  void SetTsmIPPort(const char *ipDst, const char *ipSrc, bool isCMCSrc);
  void SetRcvIPPort(const char *ipp); // set to transmit's
  void SetStreamType(STREAM_TYPE type){ fStreamType = type; }
  void SetPortId(int id){ fPortId = id; }

  const char *IPPort() const{ return fIPPort; }
  bool IsIn() const{ return fIsIn; }
  bool IsShm() const{ return fIsShm; }
  STREAM_TYPE StreamType() const{ return fStreamType; }

  friend ofstream &operator<<(ofstream &fout, const Port &port);

protected:
  bool fIsIn; ///< true: input; false: output
  bool fIsShm; ///< true: shm; false: socket
  int fLnId;
  int fPortId;

  int fLnId1; // the other LnId for shm (shm_fLnOut_fLnIn)
  char fIPPort[128]; // for socket only
  STREAM_TYPE fStreamType;
};

#endif
